﻿var vm = new Vue({
    el: '#app',
    data: function () {
        return {
            pagename: "首页",
            common_fn: null,
            userinfo: null,
            userName: null,
            // 需要权限检查的 show:false,isneedcheck:'' 需这样设置，不用权限的不用写 isneedcheck （必须）
            data: {
                addorder: { name: '订单', img: 'img/nav/订单.jpg', href: './addorder.html', appHref: './app_addorder.html', show: false, isneedcheck: '权限' },
                // workshopplan:{name:'车间计划',img:'img/nav/车间计划.jpg',href:'./workshopplan.html',appHref:'./app_workshopplan.html',show:false,isneedcheck:'权限'},
                teamplan: { name: '计划排产', img: 'img/nav/班组计划.jpg', href: './teamplan.html', show: false, isneedcheck: '权限' },
                claimwork: { name: '派工', img: 'img/nav/派工.jpg', href: './claimWork.html', show: false, isneedcheck: '权限' },
                reportwork: { name: '报工', img: 'img/nav/报工.jpg', href: './reportWork.html', show: false, isneedcheck: '权限' },
                inspection: { name: '质检', img: 'img/nav/质检.jpg', href: './inspection.html', show: false, isneedcheck: '权限' },
                transfer: { name: '物料转仓', img: 'img/nav/物料转仓.jpg', href: './transfer.html', show: false, isneedcheck: '权限' },
                reviewflow: { name: '追溯查询', img: 'img/nav/追溯查询.jpg', href: './reviewflow/reviewflow.html', show: false, isneedcheck: '权限' },
                progress: { name: '报表', img: 'img/nav/报表.jpg', href: './reportnav.html', show: true },
                mywork: { name: '我的任务', img: 'img/nav/我的任务.jpg', href: './myWork.html', show: false, isneedcheck: '权限' },
                // notice:{name:'消息通知',img:'img/notice.png',href:'./notice.html',show:true},
                // rollbackbeginwork:{name:'开工撤销',img:'img/rollbackbeginwork.png',href:'./notice.html',show:true},
            },
            wait_state: 0,
            //组件信息
            differentComponentDialog: null,
            differentComponentItem: null
        }
    },
    methods: {
        jump: function (href) {
            window.location.href = href;
        },
        //APP
        jumpApp: function (appHref) {
            window.location.href = appHref;
        },
        closeWait: function (state) {
            var self = this;
            var arr = JSON.stringify(self.data).match(/[权限]/ig);
            if (state == arr.length / 2) {
                waitClose();
            }
        },
    },
    mounted: function () {
        var self = this;
        $(document).ready(function () {
            waitStart();
        })
        self.common_fn = new common_fn();
        self.common_fn.init(function () {
            self.common_fn.UserInfo(function (response) {
                if (response.user == null) {
                    window.location.href = 'login.html?redirect=index.html';
                }
                self.userinfo = response;
                self.userName = self.userinfo.user.properties.name
                // 权限检查
                // 开工
                self.common_fn.CheckFunction(self.userinfo, 'mes', 'mes', 'PersonBeginWork', '', '', null, function (res) {
                    if (res) { self.data.claimwork.show = true }; self.closeWait(++self.wait_state)
                })
                // 报工
                self.common_fn.CheckFunction(self.userinfo, 'mes', 'mes', 'SwingCardReportWork', '', '', null, function (res) {
                    if (res) { self.data.reportwork.show = true }; self.closeWait(++self.wait_state)
                })
                // 质检
                self.common_fn.CheckFunction(self.userinfo, 'mes', 'mes', 'QualityInspect', '', '', null, function (res) {
                    if (res) { self.data.inspection.show = true }; self.closeWait(++self.wait_state)
                })
                // 订单
                self.common_fn.CheckFunction(self.userinfo, 'mes', 'mes', 'OrderMgr', '', '', null, function (res) {
                    if (res) { self.data.addorder.show = true }; self.closeWait(++self.wait_state)
                })
                // 班组计划
                self.common_fn.CheckFunction(self.userinfo, 'mes', 'mes', 'TeamPlanMgr', '', '', null, function (res) {
                    if (res) { self.data.teamplan.show = true }; self.closeWait(++self.wait_state)
                })
                // 车间计划
                self.common_fn.CheckFunction(self.userinfo, 'mes', 'mes', 'WorkShopPlanMgr', '', '', null, function (res) {
                    if (res) { self.data.workshopplan.show = true }; self.closeWait(++self.wait_state)
                })
                // 物料转仓
                self.common_fn.CheckFunction(self.userinfo, 'mes', 'mes', 'MaterialMove', '', '', null, function (res) {
                    if (res) { self.data.transfer.show = true }; self.closeWait(++self.wait_state)
                })
                // 我的任务
                self.common_fn.CheckFunction(self.userinfo, 'mes', 'mes', 'MyWork', '', '', null, function (res) {
                    if (res) { self.data.mywork.show = true }; self.closeWait(++self.wait_state)
                })

                // 追溯查询
                self.common_fn.CheckFunction(self.userinfo, 'mes', 'mes', 'TraceSearch', '', '', null, function (res) {
                    if (res) { self.data.reviewflow.show = true }; self.closeWait(++self.wait_state)
                })
                // 开工撤销
                // self.common_fn.CheckFunction(self.userinfo,'mes','mes','RollBackBeginWork','','',null,function(res){
                //     if(res){ self.data.rollbackbeginwork.show = true }
                // })
            })
        })

    }
})

